﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace Dooshion.Utility
{
    public static class ValidateControl
    {

        public enum OperatorSymbol
        {
            等于,
            不等于,
            大于,
            小于,
            大于等于,
            小于等于,
        }

        #region 验证文本框类型
        /// <summary>
        /// 验证文本框是否为整型
        /// </summary>
        /// <param name="obj">TextBox控件</param>
        /// <param name="length">限制输入位数</param>
        /// <author>grokyao</author>
        /// <date>2012-3-5</date>
        /// <returns>True为验证成功</returns> 
        public static bool TextBoxIsInt(TextBox obj, int length)
        {
            int testtxt = 0;
            if (obj.Text.Trim().Length == 0)
            {
                return false;
            }
            if (obj.Text.Trim().Length >= length)
            {
                return false;
            }
            if (!int.TryParse(obj.Text.Trim(), out testtxt))
            {
                return false;
            }
            return true;
        }

        /// <summary>
        /// 验证文本框是否为小数
        /// </summary>
        /// <param name="obj">TextBox控件</param>
        /// <param name="length">限制输入位数</param>
        /// <author>grokyao</author>
        /// <date>2012-3-5</date>
        /// <returns>True为验证成功</returns> 
        public static bool TextBoxIsDecimal(TextBox obj, int length)
        {
            decimal testtxt = 0;
            if (obj.Text.Trim().Length == 0)
            {
                return false;
            }
            if (obj.Text.Trim().Length >= length)
            {
                return false;
            }
            if (!decimal.TryParse(obj.Text.Trim(), out testtxt))
            {
                return false;
            }
            return true;
        }

        /// <summary>
        /// 验证文本框是否为日期
        /// </summary>
        /// <param name="obj">TextBox控件</param>
        /// <author>grokyao</author>
        /// <date>2012-3-5</date>
        /// <returns>True为验证成功</returns> 
        public static bool TextBoxIsDate(TextBox obj)
        {
            DateTime testtxt;
            if (obj.Text.Trim().Length == 0)
            {
                return false;
            }
            if (!DateTime.TryParse(obj.Text.Trim(), out testtxt))
            {
                return false;
            }
            return true;
        }

        #endregion

        #region 验证文本框值

        

        #endregion

    }
}
